var express = require('express');
const boksme = require('../bin/模型基础信息');
const router = express.Router();
const moment = require('moment')

/* GET home page. */
router.get('/account', function (req, res, next) {
    console.log(req.query);
    boksme.find().then((data) => {
        res.render('account', { accounts: data, url: req.url + '/create', moment: moment })
    })
});


//删除id请求
router.get('/account/create/:id', function (req, res, next) {
    let id = req.params.id;

    boksme.deleteOne({ _id: id }).then((data) => {
        console.log(data);
    }).catch((err) => {
        console.log(err);
    })
    res.render('success', { msg: '删除成功', url: '/account' });
});


router.get('/account/create', function (req, res, next) {
    res.render('create');
});



//提交添加请求
router.post('/account', (req, res) => {
    console.log(req.query);
    boksme.create(req.body).then((data) => {
        console.log(data);
    }).catch((err) => {
        console.log(err);
    })
    res.render('success', { msg: '添加成功', url: req.url })
})

module.exports = router;
